﻿using System;
using FinPlusComponents;
using QLNet;
using p = FinPlusAnalytics.QLConvParser;

namespace FinPlusAnalytics
{
    public class FlatForwardCurve : FinPlusComponent
    {
        public string Name { get; private set; }
        public FlatForward FlatForward { get; private set; }
        public SwapEngine SwapEngine { get; private set; }

        //construct
        public FlatForwardCurve(string marketName, string name, string discountCurveName, DateTime settlementDate, double rate, string dayCount, string holidays = "")
        {
            Name = name;
            var market = Markets.Instance.GetMarket(marketName); 
            var calendar = p.Calendar(holidays);
		    
		    FlatForward = new FlatForward(calendar.adjust(settlementDate), new Handle<Quote>(new SimpleQuote(rate)), p.DayCount(dayCount));
            SwapEngine = new SwapEngine(market, name, discountCurveName == "" ? name : discountCurveName);
        }

        public FlatForwardCurve(string marketName, string name, string discountCurveName, DateTime settlementDate, double rate, string dayCount, string cpnFrq, string compounding, string holidays = "")
        {
            Name = name;
            var market = Markets.Instance.GetMarket(marketName);
            var calendar = p.Calendar(holidays);
    
		    FlatForward = new FlatForward(calendar.adjust(settlementDate), new Handle<Quote>(new SimpleQuote(rate)), p.DayCount(dayCount),
                p.Compounding(compounding), p.Freq(cpnFrq));

            SwapEngine = new SwapEngine(market, name, discountCurveName == "" ? name : discountCurveName);
        }
    }
}
